/*
 * (C) 2012 Sheng Yi
 * This program judes the valid  of a telephont number.
 */
#include <stdio.h>
#include <string.h>

int verifyMsisdn(char* inMsisdn);

int main()
{
	char inMsisdn[100];
	int i;
	for (i = 0; i < 100; i++)
	{
		if ((inMsisdn[i] = getchar()) == '\n')
		{
			inMsisdn[i] = '\0';
			break;
		}
	}
	int res = verifyMsisdn(inMsisdn);
	switch (res)
	{
	case 0:
		printf("The number is valid.\n");
		break;
	case 1:
		printf("Invalid number: unexcept length!\n");
		break;
	case 2:
		printf("Invalid number: contains unexcept charactors!\n");
		break;
	case 3:
		printf("Invalid number: not starts with 86!\n");
			break;
	default:
		break;
	}

	return 0;
}

int verifyMsisdn(char* inMsisdn)
{
	// the length must be 13
	if (strlen(inMsisdn) != 13)
		return 1;

	int i;
	for (i = 0; i < 13; i++)
	{
		// the number contains non-numberic charactors
		if (inMsisdn[i] < '0' || inMsisdn[i] > '9')
			return 2;
	}
	
	// the first two number must be 86
	if (!((inMsisdn[0] == '8') && (inMsisdn[1] == '6')))
		return 3;

	return 0; // the number is OK!
}
